<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>我的申请</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="/Woniu/Public/X-admin/css/x-admin.css" media="all">
    </head>
    <body>
        <div class="x-nav">
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:29px">ဂ</i> <i class="layui-icon" style="line-height:30px">刷新</i></a>
        </div>

        <xblock style="height:40px" >
      		<button class="layui-btn" onclick="passAll()"><i class="layui-icon">&#xe608;</i>批量同意</button>
          <button class="layui-btn layui-btn-danger" onclick="notpassAll()"><i class="layui-icon"></i>批量拒绝</button>
        </xblock>

        <div class="layui-tab">
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
        
					<table class="layui-table">
					  <colgroup>
              <col width="5%">
					    <col width="10%">
					    <col width="15%">
              <col width="15%">
              <col width="10%">
					    <col width="15%">
					    <col>
					  </colgroup>
					  <thead>
					    <tr>
                <th><input type="checkbox" id="all" onchange="dianji()" value="" title="全选" lay-skin="primary"></th>
					      <th>申请人</th>
					      <th>起始日期</th>
					      <th>终止日期</th>
					      <th>请假天数</th>
					      <th>请假原因</th>
                <th>请假状态</th>
					      <th>进行审核</th>
					    </tr> 
					  </thead>
					  <tbody>
		            <form class="layui-form" action="" method="post">
			              <?php if(is_array($list)): foreach($list as $key=>$row): ?><tr>
                        <td><input type="checkbox" name="ck" value="<?php echo ($row['id']); ?>"></td>
    							      <td><?php echo ($row['pid']); ?></td>
    							      <td><?php echo ($row['start_time']); ?></td>
    							      <td><?php echo ($row['end_time']); ?></td>
    							      <td><?php echo ($row['day']); ?></td>
    							      <td><?php echo ($row['cause']); ?></td>
                        <td><?php echo ($row['status']); ?></td>
    							      <td class="td-manage">
                      <a title="同意请假" href="javascript:;" onclick="admin_pass(this,'<?php echo ($row['id']); ?>')" class="ml-5" style="text-decoration:none"><i style="font-size: 30px; color: #1E9FFF;" class="layui-icon">&#xe618;</i></a>&nbsp;&nbsp;&nbsp;&nbsp;
                      <a title="拒绝请假" href="javascript:;" onclick="admin_notpass(this,'<?php echo ($row['id']); ?>')" style="text-decoration:none"><i class="layui-icon" style="font-size: 30px; color: #FF5722;" >&#x1007;</i></a>
                    </td>
    							    </tr><?php endforeach; endif; ?>
			            </tbody>
			          </table>
					</form>
				<div class="total">共<?php echo ($total); ?>条数据</div>
          <!-- 分页信息 -->
          <div id="pages"></div>
				</div>
			</div>
		</div>
	
        <script src="/Woniu/Public/X-admin/lib/layui/layui.js" charset="utf-8"></script>
        <script src="/Woniu/Public/X-admin/js/x-layui.js" charset="utf-8"></script>
        <script>
          //全选   全不选
            function dianji() {
              var flag = document.getElementById("all").checked;
                  // alert(flag)
                  var cks = document.getElementsByName("ck");
                    if (flag) {
                    for ( var i = 0; i < cks.length; i++) {
                    cks[i].checked = true;
                    }
                  } else {
                  for ( var i = 0; i < cks.length; i++) {
                  cks[i].checked = false;
                  }
              }
            }
        </script>
        <script>

             layui.use(['laydate','element','laypage','layer','form'], function(){
                $ = layui.jquery;//jquery
              laydate = layui.laydate;//日期插件
              lement = layui.element();//面包导航
              laypage = layui.laypage;//分页
              layer = layui.layer;//弹出层
              form = layui.form();     

              //以上模块根据需要引入
              //调用分页
              laypage({
                cont: 'pages',
                curr: <?php echo ($curr); ?>,
                groups: 5,
                pages: <?php echo ($page); ?>, //得到总页数
                skip: true,
                jump: function(obj, first){
                  var url = window.location.href;
                  if (!first) {
                    window.location.href=url+"/p/"+obj.curr+".html";
                  }
                }
              });  
              
            });

            //监听提交
              form.on('submit(save)', function(data){
                console.log(data);
                //发异步，把数据提交给php
                layer.alert("保存成功", {icon: 6},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });
                return false;
              });

            // 批量同意
            function passAll () {

                a = [];
                $("input[name='ck']").each(function(){
                  if($(this).is(":checked")){
                    //获取被选中的复选框的id
                    id=$(this).val();
                    //把所有选中的id  存储在数组a
                    a.push(id);
                  }
                });


                if(a.length!=0){
                  layer.confirm('确认要同意请假吗？',function(index){
                      //捉到所有被选中的，发异步进行禁用

                      $.post("/Woniu/index.php/Home/Leave/passAll",{ids:a},function(data){
                        if(data=="失败"){
                          alert("失败");
                        }
                      });
                      layer.msg('已批量同意', {icon: 1});
                      reload();
                  });
                }else{
                    layer.msg('你没选中任何选项', {icon: 2});
                }
            }

            // 批量拒绝
            function notpassAll () {

                a = [];
                $("input[name='ck']").each(function(){
                  if($(this).is(":checked")){
                    //获取被选中的复选框的id
                    id=$(this).val();
                    //把所有选中的id  存储在数组a
                    a.push(id);
                  }
                });

                if(a.length!=0){
                  layer.confirm('确认要拒绝吗？',function(index){
                      //捉到所有被选中的，发异步进行禁用

                      $.post("/Woniu/index.php/Home/Leave/notpassAll",{ids:a},function(data){
                        if(data=="失败"){
                          alert("失败");
                        }
                      });
                      layer.msg('已批量拒绝', {icon: 1});
                      reload();
                  });
                }else{
                  layer.msg('你没选中任何选项', {icon: 2});
                }
            }
             /*添加*/
            function admin_add(title,url,w,h){
                x_admin_show(title,url,w,h);
            }
            //编辑
            function admin_edit (title,url,id,w,h) {
                x_admin_show(title,url,w,h); 
            }
            /*删除*/
            function admin_pass(obj,id){
                layer.confirm('确认通过审核吗？',function(index){
                    //发异步删除数据  
                    $.post("/Woniu/index.php/Home/Leave/pass",{id:id},function(data){
                      if(data=="失败"){
                          alert('审核失败');
                          // return false;
                      }
                    });
                    $(obj).parents("tr").remove();
                    layer.msg('已审核通过!',{icon:1,time:1000});
                });
            }
            function admin_notpass(obj,id){
                layer.confirm('确认要拒绝请假吗？',function(index){
                    //发异步删除数据  
                    $.post("/Woniu/index.php/Home/Leave/notpass",{id:id},function(data){
                      if(data=="失败"){
                          alert('拒绝失败');
                          // return false;
                      }
                    });
                    $(obj).parents("tr").remove();
                    layer.msg('已拒绝请假!',{icon:1,time:1000});
                });
            }
            </script>
            <script>
                function reload(){
                  location.replace(location.href);
                }
            </script>
    </body>
</html>